//
//  WBHomeViewController.swift
//  myWeibo
//
//  Created by 何达达mac on 2018/5/26.
//  Copyright © 2018年 hedada. All rights reserved.
//
let kScreenHeight = UIScreen.main.bounds.size.height
let kScreenWidth = UIScreen.main.bounds.size.width
import UIKit

class WBHomeViewController: WBBaseController,UITableViewDelegate,UITableViewDataSource {
    var myBtnClick: (()->())?
    
    lazy var homeTable  = UITableView()
    
    lazy var models: [WBHomeModel] = {
        var myModels = [WBHomeModel]()
        for i in 0 ..< 16 {
            var model = WBHomeModel()
            model.title = "ewdwedewdewdewdewd"
            model.mainTitle = "xxxxxxdewdewdewdewdewdew"
            model.imageName = "u=3444522782,982498177&fm=27&gp=0.jpg"
            myModels.append(model)
        }
        
        return myModels
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        setupTableView()
        
    }
    
    deinit {
        print("WBHomeViewController释放了")
    }
}

//mark - 设置导航条
extension WBHomeViewController{
    //设置右上角的item
    func setupUI(){
        let btn = UIButton()
        btn.setTitle("好友", for: UIControlState.normal)
        btn.setTitleColor(UIColor.orange, for: UIControlState.normal)
        btn.sizeToFit()
        btn.addTarget(self, action: #selector(leftItemClick), for: UIControlEvents.touchUpInside)
        let leftItem  = UIBarButtonItem(customView: btn)
        navigationItem.leftBarButtonItem = leftItem
    }
    
    
   @objc  private  func leftItemClick() {
    let vc = WBxxxxViewController()
     navigationController?.pushViewController(vc, animated: true)
}
    
}

//mark - 设置tableView
extension WBHomeViewController{
    func setupTableView()  {
       
        homeTable = UITableView(frame:  CGRect(x: 0, y: 64, width:kScreenWidth , height: kScreenHeight - 64 - 44 - 1), style: .plain)
        homeTable.delegate = self
        homeTable.dataSource = self
        view.addSubview(homeTable)
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return models.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = WBHomeCell.instanceCell()
        let model = models[indexPath.row]
        cell?.newModel = model
        cell?.btnClick = {
               ()->() in
        }
        return cell!
    }
    func  tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let detailVc = WBDetailHomeTableController()
        self.navigationController?.pushViewController(detailVc, animated: true)
        
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return 100
    }
    
    
}


